export default {
    data() {
        return {
            tableData: [],
            tableData2: [],
            type: 1,
            count: 0,
            page: 1,      //分页数
            limit: 10,		//条数

        }
    },
    //进入页面加载
    mounted: function () {
        var that = this;
        //在缓存中获取值
        that.user_name = sessionStorage.getItem("user_name");
        that.user_id = sessionStorage.getItem("user_id");
        that.token = sessionStorage.getItem("access-token");
        if ((!that.token) || (!that.user_id) || (!that.user_name)) {
            that.$router.push('/login');
        }

        if (that.$route.query.type) {
            that.type = that.$route.query.type;
        }

        that.getList();
    },

    //方法
    methods: {
        /**
         * 获取列表
         */
        getList() {
            let that = this;
            that.tableData = [];
            // that.count = 0;
            //请求的数据
            let formData = {};
            formData.token = that.token;

            that.$http.post(that.adminApi.api_url + "/api/orderstat/index", formData, {
                emulateJSON: true
            }).then(
                function (res) {
                    // 处理成功的结果
                    if (res.body.total) {
                        that.tableData=[{
                            total: res.body.total.count,
                            collect: res.body.total.total_price,
                            derate: res.body.total.reduction_price,
                            pay: res.body.total.pay_price,
                            actual: res.body.total.pay_price,
                            retreat: "-"+res.body.total.return_price,
                            altogether: res.body.total.income_price,
                        }];
                    }
                    if (res.body.list) {
                        for (var i in res.body.list) {
                            that.tableData2.push({
                                sort: Number(i)+1,
                                order_id: res.body.list[i].id,
                                goods_id: res.body.list[i].goods_id,
                                num: "<div class='blue'>"+ res.body.list[i].sn +"</div>",
                                place_time: res.body.list[i].create_time,
                                users_id:res.body.list[i].user_id,
                                over_time: res.body.list[i].completion_time,
                                shop_id: "<div class='blue'>"+ res.body.list[i].goods_sn +"</div>",
                                name: res.body.list[i].real_name,
                                user_id: "<div class='blue'>"+ res.body.list[i].user_no +"</div>",
                                collect: res.body.list[i].total_price,
                                derate: "-60",
                                pay: res.body.list[i].pay_price,
                                actual: res.body.list[i].pay_price,
                                retreat: "-"+res.body.list[i].return_price,
                                altogether: res.body.list[i].income_price,
                            });
                        }
                        that.count = res.body.count;
                    }
                },
                function () {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },

        /**
         * 下一页
         * @param pageNum
         */
        handleCurrentChange1: function(pageNum) {
            var that = this;
            that.page = pageNum;
        },

        /**
         * 跳转到用户详情
         */
        toUserDetail:function (e) {
            let that = this;
            that.$router.push({path: '/user/information', query: {member_id: e}});
        },


        /**
         * 跳转到订单详情
         */
        toOrderDetail: function(e) {
            let that = this;
            that.$router.push({
                path: '/order/order_detail',
                query: {order_id: e}
            });
        },

        /**
         * 跳转至详情
         */
        toGoodsDetail:function (e) {
            let that = this;
            that.$router.push({path: '/commodity/goods_detail', query: {goods_id: e}});
        }
    }
}